package com.base.vistter.iframe.inverter.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.base.vistter.iframe.bean.Result;
import com.base.vistter.iframe.entity.SysLog;
import com.base.vistter.iframe.exception.IframeException;
import com.base.vistter.iframe.service.SysLogService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
@RequestMapping("/sys/log")
public class SysLogController {
    @Resource(name = "sysLogService")
    private SysLogService sysLogService;

    @GetMapping
    public Result<Page<SysLog>> get(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(value = "pageNum", defaultValue = "10") Integer pageNum, String title) throws IframeException {
        Page<SysLog> page = Page.of(pageNo, pageNum);
        LambdaQueryWrapper<SysLog> lambdaQueryWrapper = new LambdaQueryWrapper<SysLog>();
        if (StringUtils.isNotEmpty(title)) {
            lambdaQueryWrapper.like(SysLog::getTitle , title);
        }
        lambdaQueryWrapper.orderByDesc(SysLog::getCreateDate);
        return Result.ok(sysLogService.page(page, lambdaQueryWrapper));
    }

    @DeleteMapping("/{id}")
    public Result<Integer> delete(@PathVariable("id") Integer id) throws IframeException {
        return Result.ok(sysLogService.delete(id));
    }

}